package com.wuyou.simple;

import java.util.Arrays;

/**
 * @Description 1582. 二进制矩阵中的特殊位置
 * @Author 无忧
 * @Date 2022/9/4 10:33
 */
public class NumSpecial {


    public static void main(String[] args) {
        NumSpecial numSpecial = new NumSpecial();
        int[][] mat = {{1, 0, 0},
                {0, 0, 1},
                {1, 0, 0}};

        System.out.println(numSpecial.solution_1(mat));
    }


    public int solution_1(int[][] mat) {

        int resNum = 0;

        for (int i = 0; i < mat.length; i++) {
            int[] arr = mat[i];
            int oneCount = 0;
            int lineIndex = 0;
            int columnIndex = 0;
            boolean flag = true;

            for (int j = 0; j < arr.length; j++) {
                if (arr[j] == 1) {
                    oneCount++;
                    lineIndex = j;
                }
            }
            if (oneCount == 1) {
                for (int j = 0; j < mat.length; j++) {
                    if (i != j && flag && mat[j][lineIndex] == 1) {
                        flag = false;
                    }
                }
                if (flag) {
                    resNum++;
                }
            }
        }
        return resNum;
    }
}
